<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box">盒子11</div>
    <div class="box">盒子22</div>
    <div id="nav">
        <ul>
            <li>首页</li>
            <li>产品</li>
        </ul>
    </div>
    <script>
        //1.getElementsByClassName 根据类名获取元素集合
        var boxs = document.getElementsByClassName('box');
        console.log('1.获取元素集合:', boxs);

        //2.querySelector 返回指定选择器的第一个元素对象 注意: 必须指定类型 :.box, #box
        var firstBox = document.querySelector('.box');
        console.log('2.获取第一个元素:', firstBox);
        var nav = document.querySelector('#nav');
        console.log('2.获取第一个元素:', nav);
        var li = document.querySelector('li');
        console.log('3.获取ul第一个元素:', li)

        //3.querySelectorAll() 返回指定选择器的所有元素对象集合
        var allBox = document.querySelectorAll('.box');
        console.log("4.获取对象集合:", allBox);
        var lis = document.querySelectorAll('li');
        console.log('4.获取对象集合:', lis);
    </script>
</body>
</html>